home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / contrib / kaelin / pp.nw (.txt) < prev    next >
LaTeX Document  |  1995-02-24  |  23KB  |  524 lines

  1. % For LaTeX input: noweave -x -delay filename.nw > filename.tex
  2. % For source code: noweb -t filename.nw
  3. \documentstyle[noweb,11pt]{article}
  4. \pagestyle{noweb}
  5. \noweboptions{longchunks,smallcode}
  6. \newcommand{\CEE}{{\sc C\spacefactor1000}}
  7. \newcommand{\CPP}{{\sc C\PP\spacefactor1000}}
  8. \newcommand{\ICON}{{\sc Icon\spacefactor1000}}
  9. \newcommand{\PP}{\kern.5pt\raisebox{.4ex}
  10.    {$\scriptscriptstyle+\kern-1pt+$}\kern.5pt}
  11. \begin{document}
  12. \title{Beyond the {\tt \symbol{"5C}tt} Font\\{\large A {\tt noweb} Extension}}
  13. \author{Kaelin L. Colclasure \\ {\tt kaelin@bridge.com}}
  14. \date{Preliminary Draft}
  15. \maketitle
  16. \section{Introduction}
  17. This document contains two filters for {\tt noweave}, written in \ICON,
  18. which add basic pretty-printing for \CPP\ and \ICON\ code to {\tt noweb}'s
  19. repetoir of functionality.  The bulk of the code herein is derived from
  20. \cite{kostas}, and at least a nodding familiarity with that work is assumed
  21. by this documentation.  A working knowledge of \ICON\ is, of course, a must.
  22. Refer to \cite{griswold} as necessary.
  23. \subsection{Design philosophy}
  24. While I relish the idea of inflicting my own code formatting
  25. preferences on the unsuspecting masses, I was less enthusiastic
  26. towards the prospect of writing a scanner for each target language.
  27. Besides (I adeptly rationalized), so doing would violate one of the
  28. fundamental tenets of {\tt noweb}-- that the programmer maintain
  29. control over the formatting of code.
  30. Thus, this implementaion does not address indentation or line-breaking
  31. within code chunks.  Like its predecessor, it is limited bolding target
  32. language keywords, operator substitution and other such in-line markup
  33. generation.  However, even these restricted transformations can have a
  34. marked effect on the clarity of exposition of the source code.\footnote{This
  35. is particularly true for languages like Icon which have a plethora of
  36. multi-character operators.}
  37. \subsection{Why a new implementation?}
  38. While \cite{kostas} provides an easily-extensible implementation, it also
  39. has one unfortunate limitation-- the technique used to distinguish between
  40. operators and comment delimiters relies upon those categories consisting of
  41. disjoint character sets\footnote{More precisely, it relies upon the {\em
  42. start sets} of those two categories of tokens being disjoint.} in the target
  43. language.  While true for the target languages Kostas implemented, this
  44. assertion does not hold for a large class of commonly used languages.  The
  45. \CEE\ lagnuage, for instance, uses \verb|/*| \ldots \verb|*/| to bracket
  46. comments when both \verb|/| and \verb|*| are operators as well.
  47. While obviously a problem for me, since my first target language was \CPP,
  48. this could undoubtably have been redressed with relatively minor surgery to
  49. \cite{kostas}.  However, once I'd familiarized myself with Kostas' code, I
  50. felt compelled to add some additional tweaks and features of my own.  The
  51. principle enhancements provided are as follows:
  52. \begin{itemize}
  53. \item A more versatile scheme for handling token recognition.  This not only
  54. addresses the problem outlined above, but makes it possible to do target
  55. language dependent processing during scanning as well as during
  56. initialization.
  57. \item More robust handling of string constants.  Kostas did not deal with
  58. escaped embedded quoting characters at all.
  59. \item Pretty-printing of [[[[quoted]]]] code as well as code in {\tt noweb}
  60. chunks.
  61. \item Use of \ICON s conditional compilation facilities to allow all the code
  62. for different targets to reside in one file.\footnote{Well, {\em I} like it
  63. better this way\ldots}
  64. \end{itemize}
  65. Along the way, there have been some steps backwards as well:
  66. \begin{itemize}
  67. \item I make no provisions for multi-line comments at all.  I
  68. personally use them only for commenting out code regions, and in that
  69. context special treatment is undesirable.\footnote{This does not
  70. preclude other target language implementations based upon this work
  71. from using target language dependent code to deal with multi-line
  72. comments.}
  73. \item Font utilization has been restricted to the Computer Modern fonts
  74. provided with all implementations of \TeX\ (primarily because my
  75. site has only those fonts).
  76. \item Due to my ignorance of ``vanilla'' \TeX, the markup code generated
  77. is \LaTeX\ dependent (I was tempted to add this as an item to the list
  78. above, but decided to refrain from provoking any nasty EMail).
  79. \end{itemize}
  80. No doubt I have introduced some new bugs as well, but discovering those is
  81. left as an excercise for the reader.
  82. \section{Implementation}
  83. Like Kostas, I have split the implementation of each target filter into a
  84. common part and a target dependent part.  However, in contrast with
  85. \cite{kostas}, I have kept all the pieces together in one {\tt noweb} input
  86. file.  Readers interested only in adding a new target should read \S
  87. \ref{reqs} and then skim \S \ref{c} and \S \ref{icon} for complete examples.
  88. \subsection{Target requirements\label{reqs}}
  89. \paragraph{Minimal implementation:}
  90. Each target implementation must provide at least the following:\footnote{In
  91. point of fact, the list of keywords could be left null.  It merely provides
  92. a convenient way to populate the [[translation]] table with the
  93. language's reserved words, which will likely all receive the same markup
  94. treatment.  However, here again, Icon is an exception\ldots}
  95. \begin{itemize}
  96. \item A root chunk which generates the \ICON\ source file for the target
  97. language filter.
  98. \item A table containing all of the target languages ``interesting''
  99. character sequences and either their typographic translation {\em or an \ICON\
  100. procedure for deriving it}. 
  101. \item A list of keywords.
  102. \item A list of operators.  For our purposes here, comment-delimiting
  103. punctuation marks are considered operators.
  104. \end{itemize}
  105. Variables to hold the required table and lists exist at global scope.
  106. <<Global declarations>>=
  107. global translation                     # Table of typographic translations
  108. global keyword_list, operator_list     # List of keywords, operators
  109. \paragraph{The [[translation]] table:} The table of typographic substitutions
  110. is built by the following code chunk during program initialization:
  111. <<Define the [[translation]] table>>=
  112. translation := table();
  113. <<Keywords>>
  114. <<Operators>>
  115. \paragraph{Initial character sets:}
  116. The {\em start sets} for the two classes of tokens are defined globally in
  117. the following two chunks.  Note that [[op_chars]] is automatically derived
  118. from the list of operators already defined above.  However, some target
  119. languages will require adjustments to the definition of
  120. [[id_chars]].\footnote{Note that the Icon implementation does {\em not}
  121. add $\&$ to this list even though it prefixes some identifiers.  We treat
  122. it always as an operator instead.}
  123. <<Global declarations>>=
  124. global id_chars, op_chars
  125. <<Define initial character sets>>=
  126. id_chars := &letters ++ &digits ++ '_'
  127. op_chars := ''
  128. every op := !operator_list do op_chars ++:= cset(op[1])
  129. \paragraph{The [[begin_token]] character set:}
  130. The next two chunks globally define the {\em start set} for {\bf all}
  131. interesting tokens.  In general this will be \mbox{[[id_chars]] $\cup$
  132. [[op_chars]]}, but in some cases it may be desirable to add additional
  133. elements to this set.
  134. <<Global declarations>>=
  135. global begin_token
  136. <<Define the [[begin_token]] character set>>=
  137. begin_token := id_chars ++ op_chars
  138. \paragraph{Procedures:} 
  139. \ICON\ procedures referenced in the [[translation]] table must, of
  140. course, be defined by the target implementation.  When invoked, such a
  141. procedure will receive one argument-- the token which caused it to be
  142. invoked.
  143. Additionally, the [[TeXify]] procedure's [[case]] statement includes a
  144. target language dependent chunk which may be used to implement anything I've
  145. forgotten or neglected (like multi-line comments).  The \CEE/\CPP
  146. implementation provides a skeletal example of how this might be used to
  147. process \CEE preprocessor directives.\footnote{It takes the trouble to find
  148. them, but then merely writes them verbatim to the output with no special
  149. formatting.  This could have been more easily accomplished with a [[procedure]]
  150. entry in the [[translation]] table.}
  151. \subsection{Target independent code}
  152. \subsubsection{The [[main]] procedure}
  153. <<Procedure [[main]]>>=
  154. procedure main()
  155.    <<Define the [[translation]] table>>
  156.    <<Define initial character sets>>
  157.    <<Define the [[begin_token]] character set>>
  158.    <<Emit special \LaTeX\ definitions>>
  159.    <<Process each input line through the [[filter]] procedure>>
  160.    return
  161. <<Emit special \LaTeX\ definitions>>=
  162. write("@literal \\def\\begcom{\\begingroup\\rm" ||
  163.    "\\catcode`\\$=3\\catcode`\\^=7\\catcode`\\_=8{}}")
  164. write("@literal \\def\\endcom{\\endgroup}")
  165. <<Process each input line through the [[filter]] procedure>>=
  166. while line := read() do
  167.    line ? (="@" & filter(tab(upto(' ') | 0), if =" " then tab(0) else &null))
  168. \subsubsection{The [[filter]] procedure}
  169. <<Procedure [[filter]]>>=
  170. procedure filter(name, arg)
  171. static kind
  172. static whitespace
  173. static code_in_line
  174.    initial {
  175.       whitespace := ' \t'
  176.    case name of {
  177.       "begin": {
  178.          arg ? kind := tab(many(&letters))
  179.          copyline(name, arg)
  180.       }
  181.       "defn" | "literal" | "use": {
  182.          code_in_line := 1
  183.          copyline(name, arg)
  184.       }
  185.       "endquote": {
  186.          kind := "docs"
  187.          copyline(name, arg)
  188.       }
  189.       "nl": {
  190.          if \kind == "code" & /code_in_line then
  191.             write("@literal \\smallskip\\eatline")
  192.          copyline(name, arg)
  193.          code_in_line := &null
  194.       }
  195.       "quote": {
  196.          kind := "code"
  197.          copyline(name, arg)
  198.       }
  199.       "text": {
  200.          if \kind == "code" then {
  201.             if *(cset(arg) -- whitespace) > 0 then code_in_line := 1
  202.             TeXify(arg)
  203.          }
  204.          else copyline(name, arg)
  205.       }
  206.       default: copyline(name, arg)
  207.    return
  208. <<Procedure [[copyline]]>>=
  209. procedure copyline(name, arg)
  210.    return write("@", name, (" " || \arg) | "")
  211. \subsubsection{The [[TeXify]] procedure}
  212. <<Procedure [[TeXify]]>>=
  213. procedure TeXify(arg)
  214.    writes("@literal ")
  215.    arg ? {
  216.       while writes(preTeX(tab(upto(begin_token)))) do case &pos + 1 of {
  217.          <<Language-dependent \TeX ify chunk>>
  218.          any(id_chars):    <<Identifier or numeric constant>>
  219.          any(op_chars):    <<Operator>>
  220.          default:          stop("\n** Error at input pos ", &pos)
  221.       }
  222.       writes(preTeX(tab(0)))
  223.    write()
  224.    return rval
  225. <<Identifier or numeric constant>>=
  226.    token := tab(many(id_chars))
  227.    <<Write [[token]] or its typographic translation>>
  228. <<Operator>>=
  229.    token := tab(match(!operator_list) | &pos + 1)
  230.    <<Write [[token]] or its typographic translation>>
  231. <<Write [[token]] or its typographic translation>>=
  232. trans := translation[token]
  233. case type(trans) of {
  234.    "procedure":   writes(trans(token))
  235.    "null":        writes(preTeX(token))
  236.    default:       writes("\\mbox{" || trans || "}")
  237. <<Procedure [[preTeX]]>>=
  238. procedure preTeX(arg)
  239. static TeX, hex
  240.    initial {
  241.       TeX := '\\${}&#^_%'
  242.       hex := table();
  243.       hex["\\"] := "5C"; hex["$"] := "24"; hex["{"] := "7B"; hex["}"] := "7D"
  244.       hex["&"] := "26"; hex["#"] := "23"; hex["^"] := "5E"; hex["_"] := "5F"
  245.       hex["%"] := "25"
  246.    str := ""
  247.    every c := !arg do
  248.       str ||:= if *(cset(c) ** TeX) > 0 then "\\symbol{\"" || hex[c] || "}"
  249.          else c
  250.    return str
  251. \subsubsection{Target utility procedures}
  252. <<Procedure [[comment_eol]]>>=
  253. procedure comment_eol(arg)
  254.    return "\\begcom" || arg || tab(0) || "\\endcom"
  255. \paragraph{The [[quoted_c_string]] procedure:}
  256. This procedure matches a \CEE/\CPP-style 
  257. string constant which may contain embedded quotes escaped by a backslash
  258. (\verb|\|) character.  We want string constants to be typeset with
  259. \verb|\verb*| (ala {\tt CWEB}).  The result looks like
  260. \verb*|"a string constant"| which makes counting multiple embedded spaces
  261. {\em much} easier.
  262. <<Procedure [[quoted_c_string]]>>=
  263. procedure quoted_c_string(arg)
  264. local c, str
  265.    c := cset(arg)
  266.    str := tab(upto(c))
  267.    if \str then while str[-1] == "\\" & (*str < 2 | str[-2] ~== "\\") do
  268.       str ||:= tab(&pos + 1) || tab(upto(c))
  269.    else str := ""
  270.    str ||:= tab(&pos + 1) # Pick up closing quote
  271.    return "\\verb*\^K" || arg || str || "\^K"
  272. @ Note the use of ASCII {\tt VT} control characters to bracket the
  273. \verb|\verb*| environment.  Any target implementation which utilizes this
  274. procedure must include [[write("@literal \\catcode`^^K=3")]] in the \LaTeX\
  275. special definitions chunk. This is a gross hack, but it's made necessary by
  276. the fact that a string literal could conceiveably contain {bf all} of the
  277. printable ASCII characters.  We therefore arbitrarily choose a control
  278. character which we deem unlikely to be found in a string
  279. literal.\footnote{Incidently, my original choice was NUL, but this proved
  280. problematic for {\tt vi} users because that editor stripped the NULs away
  281. when the {\tt .tex} file was edited by hand.}
  282. \subsection{\protect\CEE/\protect\CPP\ code markup\label{c}}
  283. <<cnw.icn>>=
  284. $define LANG_CPLUSPLUS
  285. <<Global declarations>>
  286. <<Procedure [[main]]>>
  287. <<Procedure [[filter]]>>
  288. <<Procedure [[copyline]]>>
  289. <<Procedure [[preTeX]]>>
  290. <<Procedure [[TeXify]]>>
  291. <<Procedure [[comment_eol]]>>
  292. <<Procedure [[quoted_c_string]]>>
  293. <<Keywords>>=
  294. $ifdef LANG_CPLUSPLUS
  295. keyword_list := [
  296.    "asm","auto","break","case","catch","char","class","const",
  297.    "continue","default","delete","do","double","else","enum","extern",
  298.    "float","for","friend","goto","if","inline","int","long",
  299.    "new","operator","private","protected","public","register","return","short",
  300.    "signed","sizeof","static","struct","switch","template","this","throw",
  301.    "try","typedef","union","unsigned","virtual","void","volatile","while"
  302. every key := !keyword_list do translation[key] := "{\\bf{}" || key || "}"
  303. $endif
  304. <<Operators>>=
  305. $ifdef LANG_CPLUSPLUS
  306. operator_list := [
  307.    "<\<=",">>=","->","++","--","<\<",">>","<=",">=","==","!=","&&","||",
  308.    "*=","/=","%=","+=","-=","&=","^=","|=","()","[]","//","/*","*/",
  309.    "!","%","^","&","*","(",")","-","+","=","{","}","|","~","[","]","<",">",
  310.    "?","/","'","\""
  311. translation["<\<="]    := "\\protect\\OPASSIGN{\\ll}"
  312. translation[">>="]     := "\\protect\\OPASSIGN{\\gg}"
  313. translation["->"]     := "\^K\\rightharpoonup\^K"
  314. translation["++"]     := "\\protect\\PP"
  315. translation["--"]     := "\\protect\\MM"
  316. translation["<\<"]     := "\^K\\ll\^K"
  317. translation[">>"]     := "\^K\\gg\^K"
  318. translation["<="]     := "\^K\\leq\^K"
  319. translation[">="]     := "\^K\\geq\^K"
  320. translation["=="]     := "\^K\\equiv\^K"
  321. translation["!="]     := "\^K\\neq\^K"
  322. translation["&&"]     := "\^K\\wedge\^K"
  323. translation["||"]     := "\^K\\vee\^K"
  324. translation["*="]     := "\\protect\\OPASSIGN{\\ast}"
  325. translation["/="]     := "\\protect\\OPASSIGN{\\div}"
  326. translation["%="]     := "\\protect\\OPASSIGN{" || preTeX("%") || "}"
  327. translation["+="]     := "\\protect\\OPASSIGN{+}"
  328. translation["-="]     := "\\protect\\OPASSIGN{-}"
  329. translation["&="]     := "\\protect\\OPASSIGN{" || preTeX("&") || "}"
  330. translation["^="]     := "\\protect\\OPASSIGN{\\oplus}"
  331. translation["|="]     := "\\protect\\OPASSIGN{\\mid}"
  332. translation["()"]     := "\^K(\\;)\^K"
  333. translation["[]"]     := "\^K[\\;]\^K"
  334. translation["//"]     := comment_eol
  335. translation["!"]      := "\^K\\neg\^K"
  336. translation["%"]      := "\^K" || preTeX("%") || "\^K"
  337. translation["^"]      := "\^K\\oplus\^K"
  338. translation["&"]      := "\^K" || preTeX("&") || "\^K"
  339. translation["*"]      := "\^K\\ast\^K"
  340. translation["="]      := "\^K\\leftarrow\^K"
  341. translation["{"]      := "\\boldmath\^K\\{\^K"
  342. translation["}"]      := "\\boldmath\^K\\}\^K"
  343. translation["|"]      := "\^K\\mid\^K"
  344. translation["~"]      := "\^K\\sim\^K"
  345. translation["/"]      := "\^K\\div\^K"
  346. translation["'"]      := quoted_c_string
  347. translation["\""]     := quoted_c_string
  348. every op := !operator_list do /translation[op] := "\^K" || op || "\^K"
  349. $endif
  350. <<Language-dependent \TeX ify chunk>>=
  351. $ifdef LANG_CPLUSPLUS
  352. any(cpp_mark): writes(preTeX(tab(0)))
  353. $endif
  354. <<Global declarations>>=
  355. $ifdef LANG_CPLUSPLUS
  356. global cpp_mark
  357. $endif
  358. <<Define initial character sets>>=
  359. $ifdef LANG_CPLUSPLUS
  360. cpp_mark := '#'
  361. $endif
  362. <<Define the [[begin_token]] character set>>=
  363. $ifdef LANG_CPLUSPLUS
  364. begin_token ++:= cpp_mark
  365. $endif
  366. <<Emit special \LaTeX\ definitions>>=
  367. $ifdef LANG_CPLUSPLUS
  368. write("@literal \\catcode`^^K=3")
  369. write("@literal \\newcommand{\\MM}{\\kern.5pt\\raisebox{.4ex}" ||
  370.    "{\^K\\scriptscriptstyle-\\kern-1pt-\^K}\\kern.5pt}")
  371. write("@literal \\newcommand{\\PP}{\\kern.5pt\\raisebox{.4ex}" ||
  372.    "{\^K\\scriptscriptstyle+\\kern-1pt+\^K}\\kern.5pt}")
  373. write("@literal \\newcommand{\\OPASSIGN}[1]{\\raisebox{-.4ex}" ||
  374.    "{\^K\\stackrel{\\scriptscriptstyle\\,#1}{\\leftarrow}\^K}}")
  375. $endif
  376. \subsection{\protect\ICON\ code markup\label{icon}}
  377. <<inw.icn>>=
  378. $define LANG_ICON
  379. <<Global declarations>>
  380. <<Procedure [[main]]>>
  381. <<Procedure [[filter]]>>
  382. <<Procedure [[copyline]]>>
  383. <<Procedure [[preTeX]]>>
  384. <<Procedure [[TeXify]]>>
  385. <<Procedure [[comment_eol]]>>
  386. <<Procedure [[quoted_c_string]]>>
  387. <<\ICON\ [[prefixed_keyword_check]] procedure>>
  388. <<Global declarations>>=
  389. $ifdef LANG_ICON
  390. global an_word_list, ss_word_list
  391. $endif
  392. <<Keywords>>=
  393. $ifdef LANG_ICON
  394. keyword_list := [
  395.    "by","break","case","create","default","do","else","end",
  396.    "every","fail","global","if","initial","link","local","next",
  397.    "not","of","procedure","record","repeat","return","static","suspend",
  398.    "to","then","while","until"
  399. an_word_list := [
  400.    "ascii","clock","collections","cset","current","date","dateline","digits",
  401.    "error","errornumber","errortext","errorvalue","errout","fail","features",
  402.    "file","host","input","lcase","letters","level","line","main","null",
  403.    "output","pos","random","regions","source","storage","subject","time",
  404.    "trace","ucase","version",
  405. # Added in Version 8.10
  406.    "allocated","e","phi","pi","progname",
  407. # Added by X interface
  408.    "col","control","interval","ldrag","lpress","lrelease","mdrag","meta",
  409.    "mpress","mrelease","resize","rdrag","row","rpress","rrelease","shift",
  410.    "window","x","y"
  411. ss_word_list := [
  412. # Translator directives for Version 8.10
  413.    "define","else","endif","ifdef","ifndef","include","line","undef",
  414. every key := !keyword_list do translation[key] := "{\\bf{}" || key || "}"
  415. $endif
  416. <<Operators>>=
  417. $ifdef LANG_ICON
  418. operator_list := [
  419.    "#","~===:=","<\<=:=",">>=:=","~==:=","|||:=","===:=","~===","<=:=",
  420.    ">=:=","~=:=","++:=","--:=","**:=","||:=","<\<:=","==:=",">>:=",
  421.    "<\<=",">>=","~==","|||",":=:","<->","===","+:=","-:=","*:=","/:=","%:=",
  422.    "^:=","<:=","=:=",">:=","@:=","&:=","?:=","()","[]",
  423.    "<=",">=","~=","++","--","**","||","<\<","==",">>",":=","<-","{","}","|",
  424.    "+","-","?","~","=","!","@","^","*",".","/","\\","%","<","&","$","'","\""
  425. translation["#"]        := comment_eol
  426. translation["~===:="]   := "\\protect\\OPASSIGN{\\not\\equiv}"
  427. translation["<\<=:="]   := "\\protect\\OPASSIGN{\\preceq}"
  428. translation[">>=:="]    := "\\protect\\OPASSIGN{\\succeq}"
  429. translation["~==:="]    := "\\protect\\OPASSIGN{\\not\\approx}"
  430. translation["|||:="]    := "\\protect\\LONGOPASSIGN{[\\:]\\Join}"
  431. translation["===:="]    := "\\protect\\OPASSIGN{\\equiv}"
  432. translation["~==="]     := "\^K\\not\\equiv\^K"
  433. translation["<=:="]     := "\\protect\\OPASSIGN{\\leq}"
  434. translation[">=:="]     := "\\protect\\OPASSIGN{\\geq}"
  435. translation["~=:="]     := "\\protect\\OPASSIGN{\\neq}"
  436. translation["++:="]     := "\\protect\\OPASSIGN{\\uplus}"
  437. translation["--:="]     := "\\protect\\OPASSIGN{\\ni}"
  438. translation["**:="]     := "\\protect\\OPASSIGN{\\in}"
  439. translation["||:="]     := "\\protect\\OPASSIGN{\\Join}"
  440. translation["<\<:="]    := "\\protect\\OPASSIGN{\\prec}"
  441. translation["==:="]     := "\\protect\\OPASSIGN{\\approx}"
  442. translation[">>:="]     := "\\protect\\OPASSIGN{\\succ}"
  443. translation["<\<="]     := "\^K\\preceq\^K"
  444. translation[">>="]      := "\^K\\succeq\^K"
  445. translation["~=="]      := "\^K\\not\\approx\^K"
  446. translation["|||"]      := "\\protect\\OPSTACK{[\\:]}{\\Join}"
  447. translation[":=:"]      := "\^K\\leftrightarrow\^K"
  448. translation["<->"]      := "\^K\\Leftrightarrow\^K"
  449. translation["==="]      := "\^K\\equiv\^K"
  450. translation["+:="]      := "\\protect\\OPASSIGN{+}"
  451. translation["-:="]      := "\\protect\\OPASSIGN{-}"
  452. translation["*:="]      := "\\protect\\OPASSIGN{\\ast}"
  453. translation["/:="]      := "\\protect\\OPASSIGN{\\div}"
  454. translation["%:="]      := "\\protect\\OPASSIGN{" || preTeX("%") || "}"
  455. translation["^:="]      := "\\protect\\OPASSIGN{\\uparrow}"
  456. translation["<:="]      := "\\protect\\OPASSIGN{<}"
  457. translation["=:="]      := "\\protect\\OPASSIGN{=}"
  458. translation[">:="]      := "\\protect\\OPASSIGN{>}"
  459. translation["@:="]      := "\\protect\\OPASSIGN{\\partial}"
  460. translation["&:="]      := "\\protect\\OPASSIGN{\\wedge}"
  461. translation["?:="]      := "\\protect\\OPASSIGN{\\wr}"
  462. translation["()"]       := "\^K(\\;)\^K"
  463. translation["[]"]       := "\^K[\\;]\^K"
  464. translation["<="]       := "\^K\\leq\^K"
  465. translation[">="]       := "\^K\\geq\^K"
  466. translation["~="]       := "\^K\\neq\^K"
  467. translation["++"]       := "\^K\\uplus\^K"
  468. translation["--"]       := "\^K\\ni\^K"
  469. translation["**"]       := "\^K\\in\^K"
  470. translation["||"]       := "\^K\\Join\^K"
  471. translation["<\<"]      := "\^K\\prec\^K"
  472. translation["=="]       := "\^K\\approx\^K"
  473. translation[">>"]       := "\^K\\succ\^K"
  474. translation[":="]       := "\^K\\leftarrow\^K"
  475. translation["<-"]       := "\^K\\Leftarrow\^K"
  476. translation["{"]        := "\\boldmath\^K\\{\^K"
  477. translation["}"]        := "\\boldmath\^K\\}\^K"
  478. translation["|"]        := "\^K\\vee\^K"
  479. translation["?"]        := "\^K\\wr\^K"
  480. translation["~"]        := "\^K\\ni\^K"
  481. translation["!"]        := "\^K\\forall\^K"
  482. translation["^"]        := "\^K\\uparrow\^K"
  483. translation["*"]        := "\^K\\ast\^K"
  484. translation["\\"]       := "\^K\\exists\^K"
  485. translation["%"]        := "\^K" || preTeX("%") || "\^K"
  486. translation["&"]        := prefixed_keyword_check
  487. translation["$"]        := prefixed_keyword_check
  488. translation["'"]        := quoted_c_string
  489. translation["\""]       := quoted_c_string
  490. every op := !operator_list do /translation[op] := "\^K" || op || "\^K"
  491. $endif
  492. <<\ICON\ [[prefixed_keyword_check]] procedure>>=
  493. procedure prefixed_keyword_check(arg)
  494. local keyword_list, keyword, result
  495.    keyword_list := (arg == "&", an_word_list) | ss_word_list
  496.    keyword := tab(match(!keyword_list)) | &null
  497.    if \keyword then result := "{\\bf{}" || preTeX(arg) || keyword || "}"
  498.    else result := "\^K" || ((arg == "&", "\\wedge") | preTeX(arg)) || "\^K"
  499.    return result
  500. <<Emit special \LaTeX\ definitions>>=
  501. $ifdef LANG_ICON
  502. write("@literal \\catcode`^^K=3")
  503. write("@literal \\newcommand{\\LONGOPASSIGN}[1]{\\raisebox{-.4ex}" ||
  504.    "{\^K\\stackrel{\\scriptscriptstyle\\,#1}{\\longleftarrow}\^K}}")
  505. write("@literal \\newcommand{\\OPASSIGN}[1]{\\raisebox{-.4ex}" ||
  506.    "{\^K\\stackrel{\\scriptscriptstyle\\,#1}{\\leftarrow}\^K}}")
  507. write("@literal \\newcommand{\\OPSTACK}[2]{\\raisebox{-.4ex}" ||
  508.    "{\^K\\stackrel{\\scriptscriptstyle#1}{#2}\^K}}")
  509. $endif
  510. \section{Chunks}
  511. \nowebchunks
  512. \begin{thebibliography}{Mmoo}
  513. \bibitem[Gris]{griswold}Ralph E. Griswold and Madge T. Griswold. {\em
  514. The Icon Programming Language}. Prentice-Hall, Englewood Cliffs, New
  515. Jersey, 1983.
  516. \bibitem[Oiko]{kostas}Kostas N. Oikonomou. {\em Extending Noweb With
  517. Some Typesetting}. Unpublished. Included in {\tt contrib} directory
  518. of the standard {\tt noweb} distribution.
  519. \end{thebibliography}
  520. \end{document}
  521. % Local Variables:
  522. % outline-regexp: "\\([\\\]\\(sub\\)*sec\\)\\|\\(<[^>]+>>=\\)"
  523. % End:
  524.